package de.freudenreichdesign.webshop.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table (name="ORDER_ITEM")
public class ShoppingCartItem implements Serializable{

	private static final long serialVersionUID = 2789565768574322323L;
	private long shoppingCartItemID;
	private Article article;
	private int units;
	private double total;
	
	@SuppressWarnings("unused")
	private ShoppingCartItem() {}
	
	public ShoppingCartItem(Article article, int units) {
		this.article = article;
		this.units = units;
	}

	@SuppressWarnings("unused")
	private void setShoppingCartItemID(long shoppingCartItemID) {
		this.shoppingCartItemID = shoppingCartItemID;
	}

	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column (name="ORDER_ITEM_ID")
	public long getShoppingCartItemID() {
		return shoppingCartItemID;
	}

	@OneToOne
	@JoinColumn (name="ARTICLE")
	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	@Column (name="UNITS")
	public int getUnits() {
		return units;
	}

	public void setUnits(int units) {
		this.units = units;
	}

	@SuppressWarnings("unused")
	private void setTotal(double total) {
		this.total = total;
	}

	@Column (name="TOTAL")
	public double getTotal() {
		total = article.getPrice()*units;
		return total;
	}
	
}
